package 数据库;
import java.sql.*;
import java.util.Properties;

/**
 * @author oldliu
 * @since 1.0
 */
public class DBUtil {
    public static String clsName;
    public static  String url;
    public static  String user;
    public static  String pass;
    private DBUtil(){
    }
    static{
        Properties pro=new Properties();
        try {
            pro.load(DBUtil.class.getClassLoader().getResourceAsStream("prop.properties"));
            clsName=pro.getProperty("clsName");
            url=pro.getProperty("url");
            user=pro.getProperty("user");
            pass=pro.getProperty("pass");
            Class.forName(clsName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(url, user, pass);
    }

    public static void  close(ResultSet res, Statement sta,Connection con)  {
        close(res);
        close(sta);
        close(con);
    }
    public static void close(ResultSet rs){
        if(rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void close(Statement st){
        if(st!=null) {
            try {
               //st.setMaxRows(0);
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void close(Connection con){
            if(con!=null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
    }

}
